package com.wwl.cms.utils.designModeTest.prototype;

import lombok.Data;

import java.io.Serializable;

/**
 * @author wwl
 * @version 1.0
 * @date 2021/9/5 21:53
 * @description:
 */
@Data
public class DeepProtoType implements Serializable,Cloneable {
    public String name;
    public DeepCloneableTarget deepCloneableTarget;//引用类型
    public DeepProtoType(){
        super();
    }

    public DeepProtoType(String name, DeepCloneableTarget deepCloneableTarget) {
        this.name = name;
        this.deepCloneableTarget = deepCloneableTarget;
    }

    //深拷贝
    @Override
    protected Object clone()throws CloneNotSupportedException{
        Object deep = null;
        //这里完成对基本数据类型(属性)和String的克隆
        deep= super.clone();
       //对引用类型的属性，进行单独处理
       DeepProtoType deepProtoType = (DeepProtoType)deep;
       deepProtoType.deepCloneableTarget = (DeepCloneableTarget)deepCloneableTarget.clone();
       return deepProtoType;
    }

}
